//package com.calmcar.adas.cdw;
//
//import android.content.Context;
//
//import com.calmcar.adas.AdasDrawView3;
//import com.calmcar.adas.apiserver.AdasConf;
//import com.calmcar.adas.apiserver.AdasServer;
//import com.calmcar.adas.apiserver.model.AdasPoint;
//import com.calmcar.adas.apiserver.model.AdasRect;
//import com.calmcar.adas.apiserver.model.CdwDetectInfo;
//import com.calmcar.adas.apiserver.model.FrontCarInfo;
//import com.calmcar.adas.apiserver.model.LdwDetectInfo;
//import com.calmcar.adas.apiserver.out.CvCameraViewFrame;
//import com.calmcar.adas.apiserver.out.DetectInitSuccessListener;
//import com.calmcar.adas.conf.Constant;
//import com.calmcar.adas.dao.CalmCarDetectData;
//import com.calmcar.adas.service.FileProcessServer;
//import com.calmcar.adas.service.MatProcess;
//import com.calmcar.adas.util.CarSafeDistanceUtil;
//import com.calmcar.adas.util.FrontCarLaunchUtil;
//import com.google.gson.Gson;
//
//import org.opencv.core.Mat;
//import org.opencv.imgproc.Imgproc;
//
//import java.util.List;
//
//import tianjin.calmcar.calmcar_adas.AdasCarWraper;
//
///**
// * Created by lelexiao on 2018/5/7.
// */
//
//public class CdwServer {
//
//    public AdasCarWraper test;
//
//    public static String kmiStr;
//
//    public CdwServer() {
//        test=new AdasCarWraper();
//    }
//
//
//    public void init(Context mContext){
//        FileProcessServer.setCDWConf(mContext,kmiStr);
//        FileProcessServer.setCDWConfForHalf(mContext,kmiStr);
//        test.carInit();
//        test.carStart();
//        if(detectInitSuccessListener!=null ){
//              detectInitSuccessListener.onInitSuccess();
//         }
//    }
//
//    public void setDetectInitSuccessListener(DetectInitSuccessListener detectInitSuccessListener) {
//        this.detectInitSuccessListener = detectInitSuccessListener;
//    }
//
//    private DetectInitSuccessListener detectInitSuccessListener;
//
//    public CdwDetectInfo carDetectProcessForCameraView(CvCameraViewFrame inputStream){
//        Mat matGry = inputStream.gray() ;
//
//        if (matGry == null) {
//            return  null;
//        }
//        CdwDetectInfo cdwDetectInfo=new CdwDetectInfo();
//        cdwDetectInfo.setStartTime(System.currentTimeMillis());
//        byte[] bufferTemp= MatProcess.processRgbDataToByteData(matGry );
//        long start = System.currentTimeMillis(); //获取开始时间
////      String result= test.carDetect(bufferTemp,matGry  .height(),matGry  .width());
//        //20180806-mod
//        String result;
//        if(AdasServer.getInstance().getRate() > 10){
////            result= test.carDetectHalf(bufferTemp,matGry  .height(),matGry  .width());
//              result= test.carDetect(bufferTemp,matGry  .height(),matGry  .width());
//              cdwDetectInfo.setShowType(1);
//        }else{
////                result= test.carDetectHalf(bufferTemp,matGry  .height(),matGry  .width());
//              result= test.carDetect(bufferTemp,matGry  .height(),matGry  .width());
//                cdwDetectInfo.setShowType(0);
//        }
//        cdwDetectInfo.setShowType(1);
//        long end = System.currentTimeMillis(); //获取结束时间
//        Gson gson = new Gson();//来源于Gson.jar
//        CalmCarDetectData carinfoBean = gson.fromJson(result, CalmCarDetectData.class);
//        System.out.println("car detect time ： " +start +"-----"+ (end - start) + "ms");
//        if( carinfoBean==null ) return null;
//        List< CalmCarDetectData.CarPointBean> carsArray = carinfoBean .getCarPoint();
//
//        if(carsArray ==null ) return null;
//        for(int m=0;m< carsArray.size();m++){
//            CalmCarDetectData.CarPointBean  cur=carsArray.get(m);
//            AdasRect adasRect=new AdasRect(
//                    new AdasPoint ( cur.getX0(), cur.getY0()),
//                    new AdasPoint (cur.getX1(),cur.getY1())
//            );
//            double frontCarWidth=cur.getX1()-cur.getX0();
//            double adsDis=convertImageDis(1.8,frontCarWidth);
//            adasRect.setAbsDis(adsDis);
//            if(!AdasConf.CHECK_OK){
//                adasRect.setShowDis(false);
//            }else{
//                adasRect.setShowDis(true);
//            }
//            cdwDetectInfo.carRects.add(adasRect);
//        }
//        return cdwDetectInfo;
//    }
//
//
//
//    public  double convertImageDis(double carWidth,double frontCarWidth){
//        double result=0;
//        result=AdasConf.CONVERT_PARA *  (carWidth/frontCarWidth)-AdasConf.CAR_HEAD;
//        return result;
//    }
//
////    /**
////     * 设置视野焦点
////     * @param mv_x
////     * @param mv_y
////     */
////    public void setVPPara (int mv_x,int mv_y){
////            test.setVPPara((float) mv_x,(float) mv_y);
////    }
//
//
//
//
//}
